package com.cucn.oss.controller;

import com.cucn.commonutils.Result;
import com.cucn.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;

/**
 * @author KouChaoJie
 * @since: 2021/9/28 15:06
 */
//@CrossOrigin
@RestController
@RequestMapping("/eduoss/fileoss")
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * 上传头像的方法
     *
     * @param file 上传的头像文件
     * @return Result
     */
    @PostMapping
    public Result uploadOssFile(MultipartFile file) throws FileNotFoundException {
        //获取上传的文件 MultipartFile
        //获取上传到oss的地址
        String url = ossService.uploadFileAvatar(file);

        return Result.ok().data("url", url);
    }
}
